package com.leetcode.algorithm.y22.m08.w3;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 111. 二叉树的最小深度
 * 
 * https://leetcode.cn/problems/minimum-depth-of-binary-tree/
 * 
 * @author jie.deng
 *
 */
class Question0111Solution01 {

	public int minDepth(TreeNode root) {
		if (root == null) {
			return 0;
		}
		if (root.left == null) {
			return 1 + minDepth(root.right);
		} else if (root.right == null) {
			return 1 + minDepth(root.left);
		}
		int minDepthLeft = minDepth(root.left);
		int minDepthRight = minDepth(root.right);
		return 1 + Math.min(minDepthLeft, minDepthRight);
	}

}